<template>
    <view>
        <scroll-view :scroll-y="true" :scroll-x="false">
            <swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
                <block>
                    <swiper-item>
                        <image mode="scaleToFill" :src="course.videoCover" v-if="course.videoUrl == null" />
                        <video
                            mode="scaleToFill"
                            :src="course.videoUrl"
                            v-if="course.videoUrl != null"
                            class="media"
                            :show-center-play-btn="true"
                            :enable-play-gesture="true"
                            controls
                            loop
                        />
                    </swiper-item>
                </block>
            </swiper>
            <view style="display:flex;">
              <view class="title">{{ course.courseTitle }}</view>
              <view class="price">{{ course.courseLabelNames }}</view>
            </view>
            <view class="info">
                <text>{{ course.courseContent }}</text>
            </view>
        </scroll-view>
        <view style="margin-top:102%">
          <button type="default" @click="share">分享</button>
          <uniPopup ref="popup" type="share">
            <uniShare title="分享到" @select="select"></uniShare>
          </uniPopup>
        </view>
    </view>
</template>

<script>
var config = require('../../../config.js');
var http = require('../../../utils/httpHelper.js');
import uniPopup from "@/components/uni-popup/uni-popup.vue";
import uniShare from "@/components/uni-popup-share-wx/uni-popup-share-wx.vue";
export default {
    components: {
			uniPopup,
			uniShare
		},
    data() {
        return {
            userInfo: {},
            isLogin: false,
            course: {
                videoCover: '',
                videoUrl: '',
                courseTitle: '',
                courseLabelNames: '',
                courseContent: ''
            },
            indicatorDots: true,
            //是否显示面板指示点
            autoplay: true,
            //是否自动切换
            interval: 5000,
            //自动切换时间
            duration: 1000,
            //滑动时间
            buyCount: 1
        };
    },
    onLoad: function (options) {
        var that = this;
        let userInfo = uni.getStorageSync('user');
        if (userInfo != null && userInfo != undefined && userInfo != {} && userInfo != '') {
            that.setData({
                isLogin: true,
                userInfo: userInfo
            });
        } else {
            uni.setStorageSync('inviteId', options.inviteId);
        }
        var id = options.id;
        that.getCourseInfo(id);
    },
    onShow: function () {
        let userInfo = uni.getStorageSync('user');
        if (userInfo != null && userInfo != undefined && userInfo != {} && userInfo != '') {
            this.setData({
                isLogin: true,
                userInfo: userInfo
            });
        }
    },
    /*onShareTimeline() {
        var course = this.course;
        var url = '/pages/course/detail/index?id=' + course.id + '&inviteId=' + this.userInfo.userId;
        return {
            title: course.courseTitle,
            path: url,
            imageUrl: course.videoCover,
            desc: course.courseContent
        };
    },
    onShareAppMessage() {
        var course = this.course;
        var url = '/pages/course/detail/index?id=' + course.id + '&inviteId=' + this.userInfo.userId;
        return {
            title: course.courseTitle,
            path: url,
            imageUrl: course.videoCover,
            desc: course.courseContent
        };
    },*/
    methods: {
        getCourseInfo: function (id) {
            var that = this;
            var data = {
                id: id
            };
            http.httpGet(config.clubApi.getCourseInfo, data, function (res) {
                if (res.code == '200') {
                    var course = res.data;
                    that.setData({
                        course: course
                    });
                }
            });
        }
    }
};
</script>
<style lang="scss">
@import './index.scss';
</style>
